package com.huike.clues.service.impl;


import com.huike.clues.domain.TbClue;
import com.huike.clues.domain.TbClueTrackRecord;
import com.huike.clues.domain.vo.ClueTrackRecordVo;
import com.huike.clues.mapper.TbClueMapper;
import com.huike.clues.mapper.TbClueTrackRecordMapper;
import com.huike.clues.service.ITbClueTrackRecordService;
import com.huike.common.core.domain.AjaxResult;
import com.huike.common.exception.CustomException;
import com.huike.common.utils.DateUtils;
import com.huike.common.utils.SecurityUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 线索跟进记录Service业务层处理
 * @date 2022-04-22
 */
@Service
public class TbClueTrackRecordServiceImpl implements ITbClueTrackRecordService {
    @Autowired
    private TbClueTrackRecordMapper tbClueTrackRecordMapper;
    @Autowired
    private TbClueMapper tbClueMapper;
    //添加
    @Override
    public void add(ClueTrackRecordVo tbClueTrackRecord) {
           //构建线索跟进记录对象
           TbClueTrackRecord tbCTR = new TbClueTrackRecord();
           //获取用户名
        String username = SecurityUtils.getUsername();
        tbCTR.setCreateBy(username);
        tbCTR.setCreateTime(DateUtils.getNowDate());
           //属性赋值
           BeanUtils.copyProperties(tbClueTrackRecord,tbCTR);
           //构建线索管理对象
           TbClue tbClue = new TbClue();
           //属性赋值
           BeanUtils.copyProperties(tbClueTrackRecord,tbClue);
           //赋值枚举类，方法调用，传数字
           tbClue.setStatus(TbClue.StatusType.UNFOLLOWED.getValue());
           //id没赋值
           tbClue.setId(tbClueTrackRecord.getClueId());
           //修改线索表
           tbClueMapper.updateTbClue(tbClue);
           //添加线索跟进记录
           tbClueTrackRecordMapper.add(tbCTR);
    }
}
